import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

/// 自定义路由 PageRouteBuilder  , 渐变透明路由动画
class FadeRouter<T> extends PageRouteBuilder<T> {
  final Widget child;
  final int durationMs;
  /// 曲线动画类型
  final Curve curve;
  final RouteSettings settings;

  // 语法糖 这写法跟狗屎一样 ，
  FadeRouter( {this.child, this.durationMs = 500,this.curve=Curves.fastOutSlowIn, this.settings} )
      : super(
        pageBuilder: (context, animation, secondaryAnimation) { return child ;} ,
        settings : settings,
        transitionDuration: Duration(milliseconds: durationMs),
        transitionsBuilder: (context, animation, secondaryAnimation, child)  {
          return  FadeTransition(
            // 透明度
            opacity: Tween(begin: 0.1, end: 1.0).animate(  CurvedAnimation(parent: animation, curve:curve,) ),
            child: child,
          ) ;
        });
}